import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p003 from './p003';
import p004 from './p004';

export default async function a013(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 重新渲染p001
	const a1 = get('staff_no');
	const res1 = await nodejs<Array<{  notice_receive_no: string, inform_no: string, inform_title: string, inform_content: string, receive_time: number, sponso_no: string, sponsor: string }>>('notification-notice/zj-000001/s001',
		{
			filter: {
				pn: 1, a: a1
			}
		});
	const res2 = await nodejs('notification-notice/zj-000001/s002',
		{
			filter: {
				pn: 1, a: a1
			}
		});
	const arr1 = Array();
	const arr2 = Array();
	for (let i = 0; i < res2; i++) {
		arr2.push(res1[i].inform_no);
		arr1.push(format(res1[i].receive_time, 2));
	}
	const newres1 = res1.map((n) => {
		return { ...n, receive_time: format(n.receive_time, 2) };
	});
	const res3 = await nodejs<{ dt: Array<{ inform_no: string, sponso_no: string, sponsor: string }> }>('notification-notice/zj-000001/s003',
		{
			filter: {
				arr: arr2
			}
		});
	const newarr = newres1.map((n) => {
		for (let i = 0; i < res3.dt.length; i++) {
			if (n.inform_no === res3.dt[i].inform_no) {
				n.sponso_no = res3.dt[i].sponso_no,
					n.sponsor = res3.dt[i].sponsor;
				return n;
			}
		}
		n.sponsor = "";
		return n;
	});
	if (newres1.length > 0) {
		render(fd, newarr, p001, 'p001', 'inner');
		if (res2 > 20) {
			render(fd, res2, p004, 'p004', 'inner');
		}
	} else {
		render(fd, "", p003, 'p003', 'inner');
	}
}
